<!DOCTYPE html>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>

<body>
<div class="layuimini-container" id="vue">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">服务名称</label>
                            <div class="layui-input-block">
                                <select id="serviceNamesSelect" lay-filter="xmFilter" class="serviceNamesSelect" lay-search="" name="serviceType">
                                    <option value="">直接选择或搜索选择</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>

                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
            </div>

        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


    </div>
</div>
<script type="text/html" id="businessType">
    {{#  if(d.businessType === 5 ){ }}
    <button class="layui-btn layui-btn-xs layui-btn-normal" >上传</button>
    {{#  } }}
    {{#  if(d.businessType === 6 ){ }}
    <button class="layui-btn layui-btn-xs layui-btn">下载</button>
    {{#  } }}
    {{#  if(d.businessType === 7 ){ }}
    <button class="layui-btn layui-btn-xs layui-btn-warm">退回</button>
    {{#  } }}
</script>
<script type="text/html" id="state">
    {{#  if(d.state === true ){ }}
    <button class="layui-btn layui-btn-xs layui-btn-normal" >完成</button>
    {{#  } }}
    {{#  if(d.state === false ){ }}
    <button class="layui-btn layui-btn-xs layui-btn-danger">失败</button>
    {{#  } }}
</script>
<script src="../lib/layui-v2.7.3/layui/layui.js" charset="utf-8"></script>
<script src="../js/lay-module/treeSelect.js"></script>
<script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="../api/urlConfig.js"></script>
<script>

    function initServiceName(){
        $.ajax({
            url: ipURL + '/admin/log/getServiceNames',
            type: 'GET',
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {
                $.each(data.data.data, function (index, value) {
                    $('.serviceNamesSelect').append(new Option(value,index));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法

            },
        });
    }

    function initLevelName(){
        $.ajax({
            url: ipURL + '/admin/log/getLevels',
            type: 'GET',
            dataType: 'json',
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {
                var i = 0
                $.each(data.data.data, function (index, value) {

                    $('.levelSelect').append(new Option(value,index));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法

            },
        });
    }

    $(function () {
        initLevelName()
        initServiceName()
    })



    layui.use(['table', 'util'], function(){
        var table = layui.table
            ,util = layui.util;

        //监听单元格编辑
        table.on('edit(currentTableId)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
        });
    });

    layui.use(['form', 'table','upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        table.render({
            elem: '#currentTableId',
            // url: '../api/table.json',	
			url:ipURL+"/admin/log/file/page",
            headers:{token:localStorage.token},
			parseData: function(res){ //res 即为原始返回的数据
			    return {
			      "code": res.code, //解析接口状态
			      "msg": res.message, //解析提示文本
			      "count": res.count, //解析数据长度
			      "data": res.data.data,//解析数据列表
				  
			    };	
				
			},
			
			response: {
			            statusCode: 0//规定成功的状态码，默认：0
			        },
			text:{none: '无数据'},
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', title: 'ID', sort: true,hide:true},
                {field: 'fileName', title: '文件名', },
                {field: 'fileSize', title: '文件大小'},
                {field: 'taskName', title: '任务名称'},
                {field: 'teamName', title: '团队名称'},
                {field: 'businessType', title: '操作类型',templet: '#businessType'},
                {field: 'os', width:100,title: '操作系统'},
                {field: 'state', title: '状态',templet: '#state'},
                {field: 'userName',  title: '操作者'},
                {field: 'gmtCreated', width:200, title: '操作时间'},
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {

			var level = $("#levelSelect").val()
			var serviceType = $("#serviceNamesSelect").val()
			var content = $('input[name="content"]').val()

            //执行搜索重载
            table.reload('currentTableId', {
				
                page: {
                    curr: 1
                }
                , where: {
                    level:level,
                    serviceType:serviceType,
                    content:content,
                }
            });

            return false;
        });




        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {

             if (obj.event === 'delete') {  // 监听删除操作

                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                var ids = "";
                for(i=0;i<data.length;i++){
                    ids+=data[i].id;
                    ids+=",";
                }
                $.ajax({
                    url: ipURL + '/admin/log/file/'+ids,
                    method: 'delete',
                    beforeSend: function (request) {
                        request.setRequestHeader("token", localStorage.token);
                    },
                    success: function (res) {
                        layer.msg(res.message);
                        table.reload('currentTableId'); //刷新表格，参数为表格ID
                    },
                    error: function (data) {
                        layer.msg(res.message);
                    }
                });
            }
        });


        table.on('tool(currentTableFilter)', function (obj) {

        });

    });
</script>

</body>



</html>